package cn.zd.demo1.broadcast;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.NetworkInfo;
import android.widget.Toast;

public class MyNetChangeReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        Toast.makeText(context,"接收到网络变化广播",Toast.LENGTH_SHORT).show();
        if(intent != null) {
            NetworkInfo info = intent.getParcelableExtra("networkInfo");
            // info.getTypeName()
            // 接收到网络变更广播
            String text = String.format("网络大类:%s,小类：%s，网络制式：%s,网络状态：%s",info.getTypeName(),info.getSubtypeName(),info.getSubtype(),info.getState().toString());

            Toast.makeText(context,text,Toast.LENGTH_SHORT).show();
        }
    }
}
